/**
 * Created by Duanjy on 2018/1/30.
 */
layui.use(['element','layer','table'], function(){
    var element = layui.element;
    var $ = layui.jquery;
    var table = layui.table;
    var layer = layui.layer;
    //定义方法列表
    var funcList = {
        //新增tab
        "tabAdd":function(filter,title,content,id){
            element.tabAdd(filter, {
                title: title
                ,content: content
                ,id: id
            });
        },
        "tabChange":function(filter,id){
            element.tabChange(filter,id);
        },


    }

    //点击左侧导航菜单，在右侧添加tab选项卡
    $('.load-nav').click(function(){
        //获取左侧导航节点的id值、名称、icon
        var id = $(this).attr("id");
        var icon = $(this).children().text();
        var title = '<i class="layui-icon">'+icon+'</i>'+" "+$(this).attr("name");
        //声明tabAdd和tabChange方法
        var tabadd = funcList["tabAdd"];
        var tabChange = funcList["tabChange"];
        var tableList  = funcList[id];
        var url = "pages/"+id+".html";
        var content = "<iframe src="+ url +" id='iframe-"+ id +"' " +
            "name='iframe-"+ id +"' frameborder='0' style='width: 100%;height: 745px'" +
            " class='layui-anim layui-anim-upbit'></iframe>";

        //根据lay-id判断tab选项是否存在
        if ( $(".layui-tab-title li[lay-id="+id+"]").length > 0 )
        {
            tabChange("left-tab",id);
        }else{
            tabadd('left-tab',title,content,id);
            tabChange("left-tab",id);
        }
    });

   

});
